const http = require('http');
let data = require('./data.json');
// console.log(data);
const url = require('url');
const server = http.createServer((req, res) => {
    res.setHeader('Content-Type','text/html;charset=utf-8');
    let obj = url.parse(req.url, true);

    let {name, pwd} = obj.query;
    if(typeof name !=='undefined' && typeof pwd !== 'undefined') {
        data.forEach((item) =>{
            // console.log(typeof item.name, typeof item.pwd,'+++');
            // console.log(typeof name,typeof pwd,'***');
            if (item.name == name && item.pwd == pwd) {
                // console.log('成功');
                let str = `<h3>姓名：${name} </h3>`;
                res.write(str);
            } 
        })
    }
    // console.log(name,pwd,'---');
    // console.log(obj.query);
    // console.log(obj);
   
    res.end();
})
server.listen(9090);